<template>
  <div>
    <Breadcrumb></Breadcrumb>
    <section>
      <el-form :inline="true" :model="formInline" class="demo-form-inline">
        <el-form-item label="课程分类">
          <el-cascader :options="classify" clearable></el-cascader>
        </el-form-item>
        <el-form-item label="课程类型">
          <el-select v-model="courseNames" clearable placeholder="请选择">
            <el-option
              v-for="(item, index) in courseName"
              :key="index"
              :label="item"
              :value="index"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="课程状态">
          <el-select v-model="condition" clearable placeholder="请选择">
            <el-option label="已上架" value="1"> </el-option>
            <el-option label="已下架" value="2"> </el-option>
            <el-option label="待上架" value="3"> </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="创建时间">
          <el-date-picker
            v-model="time"
            type="daterange"
            range-separator="-"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="课程名称">
          <el-input
            v-model="formInline.user"
            placeholder="请输入课程名称关键字"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button icon="el-icon-search" @click="getCourse()">搜索</el-button>
          <el-button icon="el-icon-refresh" @click="onReset('formInline')"
            >重置</el-button
          >
        </el-form-item>
      </el-form>
      <!-- 表格数据 -->
      <el-table
        border
        stripe
        ref="multipleTable"
        :data="tableData"
        tooltip-effect="dark"
        style="width: 100%"
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" width="55" align="center">
        </el-table-column>
        <el-table-column prop="id" label="课程 ID" align="center">
        </el-table-column>
        <el-table-column prop="title" label="课程名称" align="center">
        </el-table-column>
        <el-table-column prop="classify_title" label="所属分类" align="center">
        </el-table-column>
        <el-table-column label="课程类型" align="center">
          <template slot-scope="scope">
            <span v-show="scope.row.course_type == 2">大班课</span>
            <span v-show="scope.row.course_type == 3">小班课</span>
            <span v-show="scope.row.course_type == 4">公开课</span>
            <span v-show="scope.row.course_type == 5">点播课</span>
            <span v-show="scope.row.course_type == 7">面授课</span>
            <span v-show="scope.row.course_type == 8">音频课</span>
            <span v-show="scope.row.course_type == 9">系统课</span>
            <span v-show="scope.row.course_type == 10">图文课</span>
          </template></el-table-column
        >
        <el-table-column label="上架状态" align="center">
          <template slot-scope="scope">
            <span v-show="scope.row.status == 1">已上架</span>
            <span v-show="scope.row.status == 2">已下架</span>
            <span v-show="scope.row.status == 3">待上架</span>
          </template>
        </el-table-column>
        <el-table-column
          label="序号"
          prop="sort"
          align="center"
        ></el-table-column>
        <el-table-column
          label="创建人"
          prop="created_name"
          align="center"
        ></el-table-column>
        <el-table-column
          label="创建时间"
          prop="created_at"
          align="center"
        ></el-table-column>
        <el-table-column
          label="更新时间"
          prop="updated_at"
          align="center"
        ></el-table-column>
        <el-table-column
          fixed="right"
          label="操作"
          min-width="250"
          align="center"
        >
          <template slot-scope="scope">
            <el-button @click="handleClick(scope.row)" type="text" size="small"
              >详情</el-button
            >
            <el-button type="text" size="small">编辑</el-button>
            <el-button type="text" size="small">禁用</el-button>
            <el-button type="text" size="small">删除</el-button>
            <el-button type="text" size="small">重置密码</el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[10, 20, 30, 40]"
        :page-size="pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </section>
  </div>
</template>

<script>
import Breadcrumb from "../../../components/Breadcrumb";
export default {
  name: "CourseManage",
  components: { Breadcrumb },
  data() {
    return {
      formInline: {
        user: ""
      },
      // 课程分类
      classify: [],
      // 课程类型
      courseName: [],
      courseNames: "",
      // 课程状态
      condition: "",
      // 创建时间
      time: "",
      // 表格数据
      tableData: [],
      currentPage: 1,
      pagesize: 10,
      total: 0
    };
  },
  created() {
    this.getCourseName();
    this.getClassify();
    this.getCourse();
  },
  mounted() {},
  methods: {
    // 课程分类请求
    async getClassify() {
      let { data: res } = await this.$axios.classify();
      console.log(res);
      this.classify = res.data.filter(item => {
        return item.children_num != 0;
      });
      console.log(this.classify);
    },
    // 课程类型数据请求
    async getCourseName() {
      let { data: res } = await this.$axios.courseName();
      console.log(res);
      this.courseName = res.data.course_name;
    },
    // 获取表格数据
    async getCourse() {
      let { data: res } = await this.$axios.course({
        course_classify_id: 0,
        course_type: this.courseName,
        finish_created_at: "",
        keywords: "",
        keywords_type: "title",
        limit: this.pagesize,
        page: this.currentPage,
        start_created_at: "",
        status: this.condition,
        teacher_id: ""
      });
      console.log(res);
      this.tableData = res.data.list;
      this.total = res.data.total;
    },
    // 重置按钮
    onReset() {
      this.formInline.user = "";
      this.classify = [];
      this.courseName = [];
      this.condition = "";
      this.time = "";
      this.getUsers();
    },
    // 复选框
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.pagesize = val;
      this.getUsers();
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.currentPage = val;
      this.getUsers();
    },
    // 表格中详情按钮
    handleClick() {}
  }
};
</script>

<style lang="scss" scoped>
section {
  padding: 10px;
}
</style>
